<template>
    <div>
        <el-table
                :data="tableData"
                border
                style="width: 100%">
            <el-table-column
                    prop="bookId"
                    label="图书ID"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="用户ID"
                    width="120">
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作"
                    width="100">
                <template slot-scope="scope">
                    <el-button @click="update(scope.row)" type="text" size="small">修改</el-button>
                    <el-button @click="toLend(scope.row)" type="text" size="small">借阅</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                background
                layout="prev, pager, next"
                :total="total"
                :page-size="pageSize"
                @current-change="page">
        </el-pagination>
    </div>
</template>

<script>
    export default {
        methods: {
            update(row) {
                this.$router.push({
                    path: '/updateLend',
                    query: {
                        id: row.bookId
                    }
                });
            },
            toLend(row){const _this = this;
                this.$router.push({
                    path: '/addLend',
                    query: {
                        id: row.bookId
                    }
                });
            },
            page(currentPage) {
                const _this = this;
                axios.get('http://localhost:8081/book/findCan/'+currentPage+'/3').then(function (resp) {
                    _this.tableData = resp.data.records;
                    _this.total = resp.data.total;
                })
            }
        },
        created() {
            const _this = this;
            axios.get('http://localhost:8081/book/findCan/1/3').then(function (resp) {
                _this.tableData = resp.data.records;
                _this.total = resp.data.total;
            })
        },
        data() {
            return {
                pageSize: 3,
                total: null,
                tableData: null,
            }
        }
    }
</script>